package
{
	import Box2DAS.Collision.AABB;
	import Box2DAS.Dynamics.ContactEvent;
	import Box2DAS.Dynamics.b2Body;
	
	import com.citrusengine.core.CitrusEngine;
	import com.citrusengine.core.State;
	import com.citrusengine.math.MathVector;
	import com.citrusengine.objects.CitrusSprite;
	import com.citrusengine.objects.PhysicsObject;
	import com.citrusengine.objects.platformer.Crate;
	import com.citrusengine.objects.platformer.Hero;
	import com.citrusengine.objects.platformer.MovingPlatform;
	import com.citrusengine.objects.platformer.Platform;
	import com.citrusengine.objects.platformer.Sensor;
	import com.citrusengine.physics.Box2D;
	import com.citrusengine.utils.ObjectMaker;
	
	import flash.display.FrameLabel;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.errors.InvalidSWFError;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.TextEvent;
	import flash.events.TimerEvent;
	import flash.media.Camera;
	import flash.media.Sound;
	import flash.net.URLRequest;
	import flash.text.TextExtent;
	import flash.text.engine.TextBlock;
	import flash.utils.Timer;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	
	import flashx.textLayout.conversion.PlainTextExporter;
	import flashx.textLayout.utils.CharacterUtil;
	
	import org.osflash.signals.Signal;
	import org.osmf.events.PlayEvent;
	
	public class GameState extends State
	{
		
		public function GameState()
		{
			super();
			
		}
		override public function initialize():void
		{
			super.initialize();
			
			
			var box2D:Box2D = new Box2D("Box2D") //this uses citrus engine assets
			add(box2D);
			box2D.visible = true; // replace true with false to turn off bounding boxes
			
						var groundfloor:Platform = new Platform ("groundfloor1", {width: 2000, height: 20, view: "PrisonHallgd.jpg" });
			add(groundfloor);
			groundfloor.x = -480;
			groundfloor.y = 400;
			groundfloor.offsetY = -160; // for png image
			groundfloor.offsetX = 80;

			var groundfloor2:Platform = new Platform ("groundfloor2", {width: 2000, height: 20, view: "PrisonHallgd2.jpg"});// this is where the second puzzle is
			add(groundfloor2);
			groundfloor2.x = 1600;
			groundfloor2.y = 400;
			groundfloor2.offsetY = -160;
			//groundfloor2.offsetX = 0;
			
			var groundfloor3:Platform = new Platform ("groundfloor3", {width: 2000, height: 20, view: "PrisonHallgd2.jpg"});// this is where the second puzzle is
			add(groundfloor3);
			groundfloor3.x = 3600;
			groundfloor3.y = 400;
			groundfloor3.offsetY = -160;

			
			/*var bg:CitrusSprite = new CitrusSprite("PrisonHall", {view: "PrisonHall.jpg" }); //background image
			add(bg);
			bg.parallax = 0.2;
			bg.x = 0
			bg.y = 30*/	
						
			
			var TextTwo:Platform = new Platform ("TextTwo", {width: 70, height: 20, view: "TextTwo.png", Platform:visible = true});
			add(TextTwo)
			TextTwo.x = 1050;
			TextTwo.y = 100;
			TextTwo.offsetY = 150
			TextTwo.visible=false	
			
		
				
			var Textsensor:Sensor = new Sensor ("Test", {width: 20, height: 250});
			add(Textsensor);
			Textsensor.x = 0;
			Textsensor.y = 200;
			Textsensor.onBeginContact.add(triggertwo);
			Textsensor.visible=false;
			
			var Text:Platform = new Platform("Text", {width: 20, height: 20, view: "Text.png", Platform:visible = true});
			add(Text);
			Text.x = 0;
			Text.y = 200;
			Text.offsetX = 250;
			Text.offsetY = 50
			Text.visible=false;
			
			// var MovieClip ({view: "flash.display.MovieClip"});
			//add(MovieClip)
			
			
			
			
			
			var crate:Crate = new Crate ("box", {width:50,height:80, view: "Shadow.png"})
			add(crate);
			crate.x = 400;
			crate.y = 300;
			crate.offsetY = -20;
			crate.gravity = 15;
			
			//timed light 
			var Timedlight:Sensor = new Sensor ("timedlight", {width: 50, height: 50, view: "3.Light.swf"});
			add(Timedlight)
			Timedlight.x = 3000
			Timedlight.y = 200
			Timedlight.offsetY = 200
			
			var Leave:Sensor = new Sensor ("Leave", {width: 50, height: 50, view: "Leave.png"}); //"now leave the prison..." text
			add(Leave)
			Leave.x = 1800
			Leave.y = 300	
			
			var lightsensor:Platform = new Platform("light", {width: 150, height: 100, view: "3.Light.swf",Platform:visible = true});
			add(lightsensor)
			lightsensor.x = 700;               // Light must turns on when the pressure sensor turns on
			lightsensor.y = 440;
			//lightsensor.offsetY = -170
			//lightsensor.offsetX = -190 
			lightsensor.visible=false; 
			
						
			var hero:Hero = new Hero("Hero",{width:40,height:90,x:320,y:10, view: "TheMan.png"});
			add(hero); //like add child 
			hero.x = -850;//set location
			hero.y = 240; 
			hero.jumpHeight = 25 //de-bug
			//hero.jumpHeight = 8 
			view.setupCamera(hero, new MathVector(160, 270));// camera which follows the player 
			
			var switchsensor:Sensor = new Sensor ("switch", {width: 50, height: 100})
			add(switchsensor);
			switchsensor.x = 2000;  //switch for second puzzle
			switchsensor.y = 350;
			
			var step:Platform = new Platform ("step1", {width: 800, height: 50})
			add(step);
			step.x = 2600;
			step.y = 400;
			
			var step2:Platform = new Platform ("step2", {width: 600, height: 50})
			add(step2);
			step2.x = 2600;
			step2.y = 370;

			var step3:Platform = new Platform ("step3", {width: 200, height: 50})
			add(step3);
			step3.x = 2600;
			step3.y = 340;

			
			var hole:Sensor = new Sensor ("pressureswitch", {width: 300, height: 20 /*view: "PrisonHallsection.png"*/});
			add(hole);
			hole.x = 500;
			hole.y = 620;
			hole.offsetY = -420;
			hole.onBeginContact.add(trigger); // {sensor: visible = false});//addEventListener?*/
			
			var sensor:Sensor = new Sensor ("groundfloor1", {width: 200, height: 20,  view: "rail.png" }); // just to show off the blurd railings in the forground 
			add(sensor);
			sensor.x = 350;
			sensor.y = 370;
			//	sensor.onBeginContact.add(TextBlock), "Push away your sins";// can't get the text block to appear
			
			/*var wall:Platform = new Platform ("wall", {width: 400, height: 400}) // invisible wall behind player
			wall.x = -1100;
			wall.y = 250;*/	
			
			
			var reset:Sensor = new Sensor("reset", {width: 8000, height: 20});
			add(reset);
			reset.x = 1220;
			reset.y = 890;
			reset.onBeginContact.add(resetLevel);
			
			//sound.addSound ("empty hall2.mp3")
			
			var block:Platform = new Platform("block", {width: 250, height: 20});
			add(block);
			block.x = 600;
			block.y = 850;
			
		}
		
		private function trigger(e:ContactEvent):void
		{
			var lightsensor:Platform = Platform(getObjectByName("light"));
			lightsensor.visible = true;
			
			var TextTwo:Platform = Platform(getObjectByName("TextTwo"));
			TextTwo.visible = true;
		}
		
		private function resetLevel(e:ContactEvent):void
		{
			CitrusEngine.getInstance().state = new GameState();  //This restarts the game		
		}
		private function TextBlock(e:ContactEvent):void
		{
			CitrusEngine.getInstance().state = new GameState();  //This restarts the game
			
		}
		private function triggertwo(e:ContactEvent):void
		{
			var Text:Platform = Platform(getObjectByName("Text"));
			Text.visible = true;
			
			{
				
				
				
				
				
				/*	private function _playSound():void 
				{
				CitrusEngine.getInstance(ContactEvent):void 				
				{*/
				
				//private function onTime(evt:TimerEvent):void
				//{
				//trace("finish");		
				//}
			}
		}			
	}
}
/*		{
var tmr:Timer = new Timer(5 * 1000);                //this is the games timer which will slowly decrease but for now I'm blocking out the level
tmr.addEventListener(TimerEvent.TIMER,onTime);
tmr.start();*/


